package com.fulihui.wgj.dal.mybatis.repository;

import com.fulihui.common.constants.WxRegionLevelConstants;
import com.fulihui.wgj.dal.mybatis.domain.WxRegion;
import com.fulihui.wgj.dal.mybatis.mapper.WxRegionMapper;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wang_wx
 * @date 2018-06-20
 */
@Component
public class WxRegionRepository extends BaseRepository<WxRegion> {

    @Resource
    WxRegionMapper wxRegionMapper;

    /**
     * 查询微信区域
     *
     * @param rid 区域id
     * @return
     */
    public WxRegion queryWxRegionByRid(String rid) {
        return wxRegionMapper.queryRegionByRid(rid);
    }

    /**
     * 查询微信区域
     *
     * @param level 区域等级
     * @return
     */
    public List<WxRegion> queryWxRegionByLevel(String level) {
        Example example = new Example(WxRegion.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("level", level);
        return wxRegionMapper.selectByExample(example);
    }

    /**
     * 查询微信区域--省份等级-处理了name拼接
     *
     * @return
     */
    public List<WxRegion> queryRegionForLevelProvice() {
        return wxRegionMapper.queryRegionForLevelProvice();
    }

    /**
     * 查询微信区域--城市等级-处理了name拼接
     *
     * @return
     */
    public List<WxRegion> queryRegionForLevelCity() {
        return wxRegionMapper.queryRegionForLevelCity();
    }

    /**
     * 查询省份 in
     *
     * @param pids
     * @return
     */
    public List<WxRegion> queryProvinceByPids(List<String> pids) {
        Example example = new Example(WxRegion.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andIn("pid", pids);
        criteria.andEqualTo("level", WxRegionLevelConstants.LEVEL_PROVINCE);
        return wxRegionMapper.selectByExample(example);
    }

    /**
     * 查询省份 not in
     *
     * @param pids
     * @return
     */
    public List<WxRegion> queryProvinceNotInPids(List<String> pids) {
        Example example = new Example(WxRegion.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andNotIn("pid", pids);
        criteria.andEqualTo("level", WxRegionLevelConstants.LEVEL_PROVINCE);
        return wxRegionMapper.selectByExample(example);
    }
}
